//
//  DaiKuanTableViewCell.m
//  wangzhe
//
//  Created by 李 佳伟 on 2017/11/2.
//  Copyright © 2017年 李 佳伟. All rights reserved.
//

#import "DaiKuanTableViewCell.h"
#import "JTCSM.h"

static CGFloat space = 20;
static CGFloat top = 10;
static CGFloat labelHeight = 20;

@implementation DaiKuanTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier TableViewCellType:(DaiKuanTableViewCellType)type{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.titleLabel = [UILabel initWithFrame:CGRectMake(space, top, KSCREENWidth/2-space, labelHeight) text:@"" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
        [self.contentView addSubview:self.titleLabel];
        
        switch (type) {
            case DaiKuanTableViewCellRadioButton:
                
                [self layoutRadioButtonWithIndex:reuseIdentifier isBool:NO];
                break;
            case DaiKuanTableViewCellButton:
                [self layoubutton];
                break;
            case DaiKuanTableViewCellTextField:
                [self layoutTextfield];
                break;
            case DaiKuanTableViewCellImageView:
                [self layoutImageviewWithIndex:reuseIdentifier];
                break;
                
            default:
                break;
        }
        
        [df lineViewWithHeightofTop:top*2+labelHeight superView:self.contentView spacing:-100 color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
    }
    
    return self;
}

- (void)layoutRadioButtonWithIndex:(NSString *)index isBool:(BOOL)isImageShow{
    //初始化单选按钮控件
    self.rb1 = [[ZYRadioButton alloc] initWithGroupId:isImageShow?KImageRadio:KRadio index:[index integerValue]];
    //设置Frame
    self.rb1.frame = CGRectMake(KSCREENWidth-space-22,9,22,22);
       //添加到视图容器
    [self.contentView addSubview:self.rb1];
   
}

- (void)layoubutton{
    
    self.selectButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.selectButton.frame = CGRectMake(KSCREENWidth-space-22,9,22,22);
    [self.selectButton setImage:[UIImage imageNamed:@"btn_02.png"] forState:UIControlStateNormal];
    [self.selectButton setImage:[UIImage imageNamed:@"btn_01.png"] forState:UIControlStateSelected];
    
    [self.contentView addSubview:self.selectButton];

}


- (void)layoutTextfield{
    
    self.textfield = [UITextField initWithframe:CGRectMake(KSCREENWidth/2,top, KSCREENWidth/2-space, labelHeight) backgrandColor:nil placeholder:@"" textAlignment:NSTextAlignmentRight font:14 texcolor:RGBACOLOR(89, 89, 89, 1)];
    [self.contentView addSubview:self.textfield];
}

- (void)layoutImageviewWithIndex:(NSString *)index{
    CGFloat imagesize = 20;
    self.headerIamgeV = [[UIImageView alloc]initWithFrame:CGRectMake(space, top+(labelHeight-imagesize)/2, imagesize, imagesize)];
    [self.contentView addSubview:self.headerIamgeV];
    
    [self.titleLabel removeFromSuperview];
    self.titleLabel = nil;
    self.titleLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(self.headerIamgeV)+space, top, KSCREENWidth/2-space, labelHeight) text:@"" font:14 textAlignment:NSTextAlignmentLeft texcolor:RGBACOLOR(89, 89, 89, 1) backgroundColor:nil];
    [self.contentView addSubview:self.titleLabel];
    
    [self layoutRadioButtonWithIndex:index isBool:YES];
}


@end
